package com.eascs.web.p2p.action;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.dubbo.config.annotation.Reference;
import com.eascs.app.dao.PageResult;
import com.eascs.p2p.common.service.IInvestorRecordService;
import com.eascs.p2p.common.vo.InvestRecordVO;
import com.eascs.p2p.common.vo.ModelResult;
import com.eascs.site.page.PaginationInfo;
import com.eascs.site.view.BaseRestResult;
import com.eascs.site.view.ViewContext;
import com.eascs.tag.MenuTag;
import com.eascs.web.p2p.common.BaseMasterViewController;

@Controller
@RequestMapping("/record")
public class InvestoRecordController extends BaseMasterViewController {

	@Reference
	IInvestorRecordService investorRecordService;

	@Override
	public void preHandle() {
		super.preHandle();
		ViewContext.put(MenuTag.CURRENT_MENU_CODE, "ManageInvestor");
	}
	/**
	 * @Title: index
	 * @Description: banner图列表
	 * @author 张庆奇
	 * @param vo
	 * @return
	 * @return String
	 * @throws
	 * @date 2016年7月11日 下午5:05:45
	 */
	@RequestMapping(value = "/index")
	public String index(InvestRecordVO vo) {

		vo.setPageSize(10);
		ModelResult<PageResult<Object[]>> model =investorRecordService.findPageInvestRecordEntity(vo);
		PageResult<Object[]> pageResult=new PageResult<Object[]>();
		if(model.isSuccess()){
			 pageResult = model.getModel();
		} 
			
		

		String[] titles = { "投资项目", "投资日期", "投资金额", "利息金额", "投资人" ,"投资人手机号"};
		
		
		
		String findCondition = "";
		String pageUrl = "/record/index";

		if (vo != null) {
			String title=vo.getTitle() == null ? "" : vo.getTitle();
			String name = vo.getName() == null ? "" : vo.getName();
			String mobile = vo.getMobile() == null ? "" : vo.getMobile();
			String beginCreateTime = vo.getBeginCreateTime() == null ? "" : vo.getBeginCreateTime();
			String endCreateTime = vo.getEndCreateTime() == null ? "" : vo.getEndCreateTime();

			findCondition = "?name=" + name +"&mobile=" + mobile+"&beginCreateTime=" + beginCreateTime +"&endCreateTime=" + endCreateTime+"&title=" + title  ;

			pageUrl = pageUrl + findCondition;
		}
		PaginationInfo paginationInfo = new PaginationInfo(pageResult, titles, pageUrl + "&showPage=");
		paginationInfo.setBuildPagingNavigation(true);
		paginationInfo.setFirstRenderColumnIndex(0);
		ViewContext.put("paginationInfo", paginationInfo);
		ViewContext.put("vo", vo);
		ModelResult<InvestRecordVO> recordModel=investorRecordService.findInvestRecordVO(vo);
		InvestRecordVO  investRecord=new InvestRecordVO();
		if(recordModel.isSuccess()){
			investRecord=recordModel.getModel();
			ViewContext.put("investRecord", investRecord);
		}
		
		ModelResult<Integer> investorNumModel=investorRecordService.getInvestorNum(vo);
		int investorNum=0;
		if(investorNumModel.isSuccess()){
			investorNum=investorNumModel.getModel();
			ViewContext.put("investorNum", investorNum);
		}
		BaseRestResult.refresh();
		return "/record/index";
	}
	
	

	
}
